package org.yray.tts.tx;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.annotation.JSONField;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

/**
 * {\"Action\":\"TextToStreamAudio\",\"AppId\":1,\"Codec\":\"pcm\",\"Expired\":1659780020,\"ModelType\":1,\"PrimaryLanguage\":1,\"ProjectId\":0,\"SampleRate\":8000,\"SecretId\":\"1\",\"SessionId\":\"1_tts_1659693620891keb4_0\",\"Speed\":0,\"Text\":\"<speak>是这样的，您是我行的存量优质卡户，目前可在我行享受最高额度50万元的纯信用贷款，最长可分5年还，如您有兴趣了解，我这边为您转接专职客户经理为您服务，您看可以吗？</speak>\",\"Timestamp\":1659693620,\"VoiceType\":101007,\"Volume\":8}
 */
@Data
@Slf4j
public class TtsReqParams {
    public TtsReqParams(String sid, String text, float speed, String voiceType, int volume)
    {
        this.action=ACTION_TEXTTOSTREAMAUDIO;
        this.codec=CODEC_PCM;
        this.primaryLanguage=1;
        this.sampleRate=8000;
        this.sessionId=sid;
        this.speed=speed;
        this.text=text;
        int intVoiceType=101003;
        try{
           intVoiceType=Integer.valueOf(voiceType);
        }
        catch (Exception e)
        {
            log.error("err voiceType={},use default voiceType={}",voiceType,intVoiceType);
        }
        this.voiceType=intVoiceType;
        this.volume=volume;

    }
    public  static String ACTION_TEXTTOSTREAMAUDIO="TextToStreamAudio";
    public  static String CODEC_PCM="pcm";

    @JSONField(name = "Action")
    private String action;

    @JSONField(name = "Codec")
    private String codec;

    //1
    @JSONField(name = "PrimaryLanguage")
    private Integer primaryLanguage;

    //SampleRate 8000
    @JSONField(name = "SampleRate")
    private Integer sampleRate;
    //
    @JSONField(name = "SecretId")
    private String secretId;

    @JSONField(name = "SessionId")
    private String sessionId;

    @JSONField(name = "Speed")
    private float speed;

    @JSONField(name = "Text")
    private String text;

    @JSONField(name = "VoiceType")
    private Integer voiceType;
    //1-8
    @JSONField(name = "Volume")
    private Integer volume;


    public String toJsonStr()
    {
        return JSON.toJSONString(this);
    }
}
